#include <cstdlib>

#define MAXSIZE 3

// 循环队列创建 入队 出队
typedef struct SeqQueue {
    int element[MAXSIZE];
    int front;
    int rear;
    int tag;
}SeqQueue;

SeqQueue* initQueue() {
    SeqQueue* q = (SeqQueue*)malloc(sizeof(SeqQueue));
    q->front = 0;
    q->rear = 0;
    q->tag = 0;
    return q;
}

int EnterSeqQueue(SeqQueue* queue,int data) {
    // 如果对头等于队尾,并且队列中有元素,则队满.
    if(queue->tag == 1 && queue->rear == queue->front) {
        return -1;
    }
    // 赋值,并且将对头后移.
    queue->element[queue->rear] = data;
    queue->rear = (queue->rear+1)%MAXSIZE;
    // 将队列中有元素赋值为1.代表队列有元素存在.
    queue->tag = 1;
    return data;
}

int DeleteQueue(SeqQueue* queue) {
    // 队列中没有元素直接返回错误
    if(queue->tag == 0) {
        return -1;
    }
    // 取出队尾的元素,讲队尾前移
    int data = queue->element[queue->front];
    queue->front = (queue->front+1)%MAXSIZE;
    // 如果队尾前移后等于对头,代表队列没有元素,tag置为0
    if(queue->front == queue->rear) {
        queue->tag = 0;
    }
    return data;
}

int main() {
    SeqQueue* queue = initQueue();
    EnterSeqQueue(queue,1);
    EnterSeqQueue(queue,2);
    EnterSeqQueue(queue,3);
    int data0 = EnterSeqQueue(queue,3);
    int data1 = DeleteQueue(queue);
    int data2 = DeleteQueue(queue);
    int data3 = DeleteQueue(queue);
    int data4 = DeleteQueue(queue);
}